package com.sg.java.classloader;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class CustomClassLoader extends ClassLoader {

    @Override
    protected Class<?> findClass(String name) throws ClassNotFoundException {
        try {
            Path path = Paths.get(new URI("file:///D:/MyScript/TestClassLoader.class"));
            byte[] cLassBytes = Files.readAllBytes(path);
            return defineClass(name, cLassBytes, 0, cLassBytes.length);
        } catch (IOException | URISyntaxException e) {
            throw new ClassNotFoundException();
        }
    }

}
